{% extends 'base.html' %}
{% block content %}
<div class="container mt-3">
  <div class="d-flex justify-content-between align-items-center">
    <h3>{{ software.name }}</h3>
    <div>
      <a class="btn btn-sm btn-primary" href="{% url 'assets:software_update' software.id %}">编辑</a>
      <a class="btn btn-sm btn-success" href="{% url 'assets:license_create' %}?software={{ software.id }}">新增许可</a>
      <a class="btn btn-sm btn-secondary" href="{% url 'assets:software_list' %}">返回列表</a>
    </div>
  </div>
  <dl class="row mt-3">
    <dt class="col-sm-2">厂商</dt><dd class="col-sm-10">{{ software.vendor }}</dd>
    <dt class="col-sm-2">类别</dt><dd class="col-sm-10">{{ software.category }}</dd>
    <dt class="col-sm-2">描述</dt><dd class="col-sm-10">{{ software.description|linebreaks }}</dd>
  </dl>

  <h5 class="mt-4">最近许可</h5>
  <table class="table table-sm table-striped">
    <thead><tr><th>许可密钥</th><th>数量</th><th>有效期</th><th>状态</th><th></th></tr></thead>
    <tbody>
      {% for lic in licenses %}
      <tr>
        <td><a href="{% url 'assets:license_detail' lic.id %}">{{ lic.license_key|default:'(无)' }}</a></td>
        <td>{{ lic.seats }}</td>
        <td>{{ lic.start_date }} ~ {{ lic.end_date }}</td>
        <td>{{ lic.get_status_display }}</td>
        <td><a class="btn btn-sm btn-outline-primary" href="{% url 'assets:license_update' lic.id %}">编辑</a></td>
      </tr>
      {% empty %}
      <tr><td colspan="5" class="text-center">暂无许可</td></tr>
      {% endfor %}
    </tbody>
  </table>

  <form method="post" action="{% url 'assets:software_delete' software.id %}" onsubmit="return confirm('确认删除该软件？');">
    {% csrf_token %}
    <button type="submit" class="btn btn-danger">删除软件</button>
  </form>
</div>
{% endblock %}
